package com.qtest.qandroid.service.UserServiceImp;

import com.qtest.qandroid.dao.Userdao;
import com.qtest.qandroid.entity.*;
import com.qtest.qandroid.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Yu
 * @time 2019/11/25 14:19
 */

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private Userdao userdao;
    private User user;
    private Course course;

    @Override
    public User quaryByName(String name) {
        return userdao.quaryByName(name);
    }

    @Override
    public Boolean addUser(User user) {
        if (userdao.addUser(user))
            return true;
        else return false;
    }

    @Override
    public Boolean addAttendance(AttendanceJob attendanceJob) {
        if (userdao.addAttendance(attendanceJob))
            return true;
        else return false;
    }

    @Override
    public AttendanceJob queryAttendance(String num) {

        return userdao.queryAttendance(num);
    }

    @Override
    public void stuAttednance(AttendanceRecord attendanceRecord) {
        userdao.stuAttendance(attendanceRecord);
    }

    @Override
    public void updateStuAttendance(AttendanceRecord attendanceRecord,String attendanceId) {
        userdao.updateStuAttendance(attendanceRecord,attendanceId);
    }

    @Override
    public AttendanceRecord queryByName(String record) {
        return userdao.queryByName(record);
    }

    @Override
    public Boolean login(String userId, String password,String userType) {
        user= userdao.login(userId,password,userType);
        if (user != null)
         return true;
        else return false;

    }

    @Override
    public Result<List<User>> selectAllStudentBelowCourse(String name) {
        Result<List<User>> result = new Result<>();
        List<User> list =userdao.selectAllStudentBelowCourse(name);
        if (list.size()>0){
            result.setNum("1");
            result.setData(list);
            result.setMessage("请求成功");
        }else{
            result.setNum("0");
            result.setMessage("请求无结果");
        }
        return result;
    }

    @Override
    public Result<List<User>> allStudentBleowCourse(String courseId) {
        Result<List<User>> result = new Result<>();
        List<User> list =userdao.allStudentBleowCourse(courseId);
        if (list.size()>0){
            result.setNum("1");
            result.setData(list);
            result.setMessage("请求成功");
        }else{
            result.setNum("0");
            result.setMessage("请求无结果");
        }
        return result;
    }

    @Override
    public Result<List<StudentRecord>> selectAllRecordFromOneCourse(String userId, String courseId) {
        Result<List<StudentRecord>> result = new Result<>();
        List<StudentRecord> list=userdao.selectAllRecordFromOneCourse(userId, courseId);
        if (list.size()>0){
            result.setNum("1");
            result.setData(list);
            result.setMessage("请求成功");
        }else{
            result.setNum("0");
            result.setMessage("请求无结果");
        }
        return result ;
    }

    @Override
    public Result<List<AttendanceJob>> selectAllAttendanceJob(String courseId) {
        Result<List<AttendanceJob>> result =new Result<>();
        List<AttendanceJob> list =userdao.selectAllAttendanceJob(courseId);
        if (list.size()>0){
            result.setNum("1");
            result.setData(list);
            result.setMessage("请求成功");
        }else{
            result.setNum("0");
            result.setMessage("请求无结果");
        }
        return result;
    }

    @Override
    public Result<List<StudentStatus>> selectAllRecordFromCourse(String attendanceId) {
        Result<List<StudentStatus>> result = new Result<>();
        List<StudentStatus> list =userdao.selectAllRecordFromCourse(attendanceId);
        if (list.size()>0){
            result.setNum("1");
            result.setData(list);
            result.setMessage("请求成功");
        }else{
            result.setNum("0");
            result.setMessage("请求无结果");
        }
        return result;
    }

    @Override
    public AttendanceJob newAttend(String courseId) {

        return userdao.newAtten(courseId);
    }

    @Override
    public Course courseMessage(Integer courseId) {
        return userdao.courseMessage(courseId);
    }

    @Override
    public void stopAttendance(String courseId, Integer attendanceId) {
        userdao.stopAttendance(courseId,attendanceId);
    }

    @Override
    public AttendanceRecord attendanceRecordIs(Integer attendanceId, String userId) {
        return userdao.attendanceRecordIs(attendanceId,userId);
    }


}
